from rest_framework.response import Response
from rest_framework.views import APIView
from tree.models import MyTreeNode
# Create your views here.

class mptt(APIView):
    def get(self, request, *args, **kwargs):
        # root = MyTreeNode.objects.create(name='Root Node')
        # child1 = MyTreeNode.objects.create(name='Child 1', parent=root)
        # child2 = MyTreeNode.objects.create(name='Child 2', parent=root)
        root = MyTreeNode.objects.filter(name='Root Node')
        descendants = root.get_descendants().values('id', 'name', 'parent_id')
        descendants_list = list(descendants)
        return Response(descendants_list)








class ApplyTemplateAPIView(APIView):

    def get(self, request, *args, **kwargs):
        data = {
            'control_id': 'Selector-17004810112398',
            'title': 'C1HC高清摄像头',
            'is_product': 1,
        }

        # control = ApplyTemplate.objects.filter(control_id='Selector-17004810112396')
        # # print(control)
        # parents = control.get_ancestors()
        # print(parents[0].control_id)

        # root = MyTreeNode.objects.get(name='Root Node')
        # child1 = MyTreeNode.objects.create(name='Child 1', parent=root)
        # child2 = MyTreeNode.objects.create(name='Child 2', parent=root)

        # parent_node = ApplyTemplate.objects.filter(control_id='Selector-17004810112398')
        # # 通过父节点获取子节点
        # print(ApplyTemplate.objects.get_queryset_descendants(parent_node, include_self=False))
        return Response('s')
